using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class SPMFGRNControl
    {
        #region Local Variable
        private SPMFGRNDataAccess _objDAO;
        private string business;

        #endregion Local Variable

        #region Method
        public SPMFGRNControl()
        {
            _objDAO = new SPMFGRNDataAccess();
        }
        public SPMFGRNControl(String bus)
        {
            business = bus;
            _objDAO = new SPMFGRNDataAccess();
        }

        public object BeginTransaction(ref string sErr)
        {
            return _objDAO.BeginTransaction(ref sErr);
        }
        public bool CommitTransaction(ref string sErr)
        {
            return _objDAO.CommitTransaction(ref sErr);
        }
        public bool RollbackTransaction(ref string sErr)
        {
            return _objDAO.RollbackTransaction(ref sErr);
        }
        public void SetTransaction(object o)
        {
            _objDAO.SetTransaction(o);
        }

        public SPMFGRNInfo Get(string db, string GRN_REF, ref string sErr)
        {
            return _objDAO.Get(db, GRN_REF, ref sErr);
        }

        public DataTable GetAll(string db, ref string sErr)
        {
            return _objDAO.GetAll(db, ref sErr);
        }

        public Int32 Add(string db, SPMFGRNInfo obj, ref string sErr)
        {
            return _objDAO.Add(db, obj, ref sErr);

        }

        public string Update(string db, SPMFGRNInfo obj)
        {
            return _objDAO.Update(db, obj);
        }

        public string Delete(string db, string GRN_REF)
        {
            return _objDAO.Delete(db, GRN_REF);

        }
        public Boolean IsExist(string db, string GRN_REF)
        {
            return _objDAO.IsExist(db, GRN_REF);
        }

        public string ExecuteQuery(string db, string GRNref, ref String sErr)
        {
            return _objDAO.ExecuteQuery(db, GRNref, ref  sErr);

        }

        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _objDAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }

        public string InsertUpdate(string db, SPMFGRNInfo obj)
        {
            string sErr = "";
            if (IsExist(db, obj.GRN_REF))
                sErr = _objDAO.Update(db, obj);
            else Add(db, obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {

            return SPMFGRNInfo.ToDataTable();
        }

        public string TransferIn(string db, DataRow row)
        {
            SPMFGRNInfo inf = new SPMFGRNInfo(row);
            return InsertUpdate(db, inf);

        }
        #endregion Method

    }
}
